#include "stm32f10x.h"                  // Device header
#include "Timer.h"

void PWM_Init(void){
	//一、RCC，把TIM外设和GPIO外设时钟打开
	//二、配置时基单元（PSC，CNT，ARR），也包括前面的包括时钟源选择
	//三、配置输出比较单元（CCR，输出比较模式，极性选择，输出使能）
	//四、GPIO
	//五、运行控制
	
	Timer_Init();
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
	
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//复用推挽输出
	GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStructure);
	
	//
	TIM_OCInitTypeDef TIMOCInitStructure;
	TIM_OCStructInit(&TIMOCInitStructure);
	TIMOCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
	TIMOCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
	TIMOCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
	TIMOCInitStructure.TIM_Pulse=0;		//CCR
	
	TIM_OC1Init(TIM2,&TIMOCInitStructure);
	
	

}
void PWM_SetCompare1(uint16_t Compare){
	TIM_SetCompare1(TIM2,Compare);
}
